<template>
  <el-select
    v-model="value"
    placeholder="请选择分类"
    style="width: 100%"
    @change="handleChange"
    :size="size"
    clearable
  >
    <el-option
      v-for="v in classifyData"
      :key="v.id"
      :label="v.name"
      :value="v.id"
    ></el-option>
  </el-select>
</template>
<script>
export default {
  data() {
    return {
      value: [],
      listQuery: {
        page: 1,
        limit: 9999,
        pid: 0,
        classType: '5', //1.试卷 2.考试 3.栏目 4.错题集 5论坛
        status: '1',
      },
      classifyData: [],
    }
  },
  props: {
    defaultValue: String,
    size: {
      type: String,
      default: 'large',
    },
  },
  watch: {
    defaultValue(v) {
      this.value = v
    },
  },
  mounted() {
    this.value = this.defaultValue
    this.getList()
  },
  methods: {
    async getList() {
      let res = await this.$store.dispatch('sysClassifyList', this.listQuery)
      this.classifyData = res.data
    },
    handleChange(value) {
      this.$emit('emit', value)
    },
  },
}
</script>
<style scoped lang="scss">
</style>